import {createRouter, createWebHistory} from "vue-router";
import Login from "@/views/Login.vue";
import Layout from "@/views/Layout.vue";
import UserInfo from "@/views/user/UserInfo.vue";
import ProductList from "@/views/product/ProductList.vue";
import RestPassword from "@/views/user/RestPassword.vue";
import Shopping from "@/views/shopping/Shopping.vue";
import MyHome from "@/views/user/MyHome.vue";
import MyOrders from "@/views/user/MyOrders.vue";
import MyCart from "@/views/user/MyCart.vue";
import MyAddress from "@/views/user/MyAddress.vue";
import AccountSettings from "@/views/user/AccountSettings.vue";
import ProductDetail from "@/views/shopping/ProductDetail.vue";
import UserList from "@/views/UserList.vue";
import Register from "@/views/Register.vue";
import MessageList from "@/views/MessageList.vue";
import OrderList from "@/views/OrderList.vue";



// 定义路由关系
const routes = [
  {path: '/login', component: Login},  // 一级路由
  { path: '/register', component: Register, meta: { title: '新用户注册' } }, // 新增注册路由
  {
    path: '/',
    redirect: '/login',  // 重定向
    component: Layout,
    // 子路由
    children: [
      {path: '/product/list', component: ProductList},
      {path: '/user/userList',component: UserList},
      {path: '/user/info', component: UserInfo},
      {path: '/user/resetPassword', component: RestPassword},
      {path:'/product/pageList', component: ProductList},
      {path:'/user/messageList', component: MessageList},
      {path: '/user/orderList', component: OrderList}
    ]
  },
  {path: '/shopping', component: Shopping,
  children: [{
    path: 'product/:id',
    name: 'ProductDetail',
    component: ProductDetail
  }]
  },
  {path: '/home', name: 'MyHome', component: MyHome},
  {path: '/orders', name: 'MyOrders', component: MyOrders},
  {path: '/cart', name: 'MyCart', component: MyCart},
  {path: '/address', name: 'MyAddress', component: MyAddress},
  {path: '/settings', name: 'AccountSettings', component: AccountSettings}
]

// 创建路由器
const router = createRouter({
  history: createWebHistory(), // 路由模式
  routes: routes
})

//导出暴露
export default router
